package com.weiyuwqj.server.service.noTransation;

import com.weiyuwqj.api.constant.Message;
import com.weiyuwqj.api.exception.CrowdException;
import com.weiyuwqj.api.model.BusAccount;
import com.weiyuwqj.api.model.BusAssetPackageInvest;
import com.weiyuwqj.api.model.BusAssetPackagePlan;
import com.weiyuwqj.api.model.BusAssetRepay;
import com.weiyuwqj.api.service.BasAssetsPackageService;
import com.weiyuwqj.api.service.NoTransationAssetPackagePlanService;
import com.weiyuwqj.server.mapper.BusAccountMapper;
import com.weiyuwqj.server.mapper.BusAssetPackagePlanMapper;
import com.weiyuwqj.server.mapper.BusAssetRepayMapper;
import com.weiyuwqj.server.service.invest.module.AssetPackageRepayModule;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by huzj on 2017/3/31.
 */

@Service("noTransationAssetPackagePlanService")
public class NoTransationAssetPackagePlanServiceImpl implements NoTransationAssetPackagePlanService{

    @Autowired
    BusAssetPackagePlanMapper assetPackagePlanMapper;

    @Autowired
    BusAssetRepayMapper assetRepayMapper;

    @Autowired
    BusAccountMapper accountMapper;

    @Autowired
    AssetPackageRepayModule packageRepayModule;

    @Autowired
    BasAssetsPackageService assetsPackageService;

//
//    @Override
//    public Map packageRepay(Integer packagePlanId) {
//        BusAssetPackagePlan packagePlan = assetPackagePlanMapper.selectByPrimaryKey(packagePlanId);
//
//        if (packagePlan == null) {
//            //没有找到此包计划
//            throw new CrowdException("packagePlan.not_found");
//        }
//        List<BusAssetRepay> assetRepayList = assetRepayMapper.listByPlanIdAndCurrentPeriod(packagePlanId,packagePlan.getPeriods());
//        for (BusAssetRepay assetRepay:assetRepayList) {
//            assetsPackageService.packageRepay(packagePlanId,assetRepay,packagePlan);
//        }
//        return Message.OK;
//    }

//    @Override
//    public Map brrowerPackageRepay(Integer packagePlanId) {
//        BusAssetPackagePlan packagePlan = assetPackagePlanMapper.selectByPrimaryKey(packagePlanId);
//
//        if (packagePlan == null) {
//            //没有找到此包计划
//            throw new CrowdException("packagePlan.not_found");
//        }
//        List<BusAssetRepay> assetRepayList = assetRepayMapper.listByPlanIdAndCurrentPeriod(packagePlanId,packagePlan.getPeriods());
//        //判断余额
//        for (BusAssetRepay assetRepay:assetRepayList) {
//            if (assetRepay.getStatus() != 0) {
//                //还款状态不正确
//                throw new CrowdException("item.repay.status_not_correct");
//            }
//            BusAccount account = accountMapper.getBusAccountByUserId(assetRepay.getRepayUserId());
//            if (account.getUsable().compareTo(assetRepay.getRepayAmount()) == -1) {
//                throw new CrowdException("item.repay.balance_is_not_enough");
//            }
//        }
//
//        for (BusAssetRepay assetRepay:assetRepayList) {
//            assetsPackageService.brrowerPackageRepay(assetRepay);
//        }
//        return Message.OK;
//    }
}
